package com.hbjycl.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.hbjycl.dao.TeacherDao;
import com.hbjycl.entity.Student;
import com.hbjycl.entity.Teacher;



@Repository
@Transactional
public class TeacherDaoImpl extends BaseDaoImpl<Teacher, String> implements TeacherDao
{
    @Override
    public boolean isExistByUsername(String username)
    {
        String hql = "from Teacher teacher where  teacher.username  = ?";
        Teacher teacher = (Teacher) getSession().createQuery(hql).setParameter(0, username)
                .uniqueResult();
        if (teacher != null)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    @Override
    public Teacher getTeacherByUsername(String username)
    {
        String hql = "from Teacher teacher where teacher.username = ?";
        return (Teacher) getSession().createQuery(hql).setParameter(0, username).uniqueResult();
    }
    
    @Override
    public List<Student> getStudentList(String username)
    {
        String hql = "select studentList from Teacher where username=?";
        return getSession().createQuery(hql).setParameter(0, username).list();
    }
    
       
    
    @Override
    public boolean deleteTeacherStudent(String teacherId)
    {
        String sql = "delete from student_teacher where Teacherlist_id=?";
        int result = getSession().createSQLQuery(sql).setParameter(0, teacherId).executeUpdate();
        return result > 0;
    }

    @Override
    public List<Teacher> getLockedAccounts()
    {
        String hql = "from Teacher where isAccountLocked=?";
        return getSession().createQuery(hql).setParameter(0, true).list();
    }

}
